using System.Runtime.InteropServices;
namespace GameFrame
{
    [StructLayout(LayoutKind.Explicit)]
    internal struct EntityInfo
    {
        public const int ACTIVE_BIT = -2147483648;
        public const int VERSION_MASK = 2147483647;
        [FieldOffset(0)]
        public EntityRef Ref;
        [FieldOffset(8)]
        public EntityFlags Flags;

        public static unsafe void Print(void* ptr, FramePrinter printer)
        {
            EntityInfo* entityInfoPtr = (EntityInfo*) ptr;
            printer.ScopeBegin();
            EntityRef.Print((void*) &entityInfoPtr->Ref, printer);
            printer.AddLine(string.Format("Flags: {0}", (object) entityInfoPtr->Flags));
            printer.ScopeEnd();
        }

        public static unsafe void Serialize(void* ptr, FrameSerializer serializer)
        {
            EntityInfo* entityInfoPtr = (EntityInfo*) ptr;
            EntityRef.Serialize((void*) &entityInfoPtr->Ref, serializer);
            if (serializer.Reading)
                entityInfoPtr->Flags = (EntityFlags) serializer.Stream.ReadInt();
            else
                serializer.Stream.WriteInt((int) entityInfoPtr->Flags);
        }
    }
}